package com.larry.mr2.partition2;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class FlowMapper extends Mapper<LongWritable, Text,Text, FlowBean> {

    private Text k = new Text();
    private FlowBean v = new FlowBean();

    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, FlowBean>.Context context) throws IOException, InterruptedException {

        String line = value.toString();
        String[] datas = line.split("\t");

        k.set(datas[1]);
        v.setUpFlow(Integer.parseInt(datas[datas.length - 3]));
        v.setDownFlow(Integer.parseInt(datas[datas.length - 2]));
        v.setSumFlow();

        context.write(k,v);
    }
}
